//
//  ViewController.m
//  数据库的读写封装
//
//  Created by zsgjs on 2017/2/21.
//  Copyright © 2017年 zsgjs. All rights reserved.
//

#import "ViewController.h"
#import "CustomTable.h"
#import "MHTable+Insert.h"
#import "MHTable+Query.h"
#import "MHTable+Update.h"
#import "MHTable+Delete.h"
#import "MHTable.h"
#import <pthread/pthread.h>
@interface ViewController ()

@property (nonatomic, strong) CustomTable *table;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSDictionary *dict = @{@"id": @"5", @"colunms": @"23", @"colunms1": @{@"jin": @[@"34", @123], @"cheng": @{@"la": @"kao"}}};
    NSDictionary *dict1 = @{@"id": @"6", @"colunms": @"23", @"colunms1": @12};
    NSDictionary *dict2 = @{@"id": @"7", @"colunms": @"23", @"colunms1": @1};
    NSDictionary *dict3 = @{@"id": @"8", @"colunms": @"23", @"colunms1": @12 };

//    [self.table insertModel:model to:column];
    [self.table insertFields:dict];
    [self.table insertFields:dict2];
    [self.table insertFields:dict1];
    [self.table insertFields:dict3];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//    NSDictionary *dict = @{@"name": @"mooohoo"};
//    NSDictionary *dict2 = @{@"name": @"mooo"};
//    NSDictionary *dict3 = @{@"name": @"hoo"};
//    [self.table addFieldsIfNotExist:dict3];
//    [self.table addFieldsIfNotExist:dict2];
//    [self.table insertFieldsIfNotExist:dict];
//    NSData *data = [NSData dataWithContentsOfFile:<#(nonnull NSString *)#>]
//    [self.table updateFields:@{@"names" :@"hao"} andWhere:@"id=6"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    
    
//        [self.table insertColumnIfNotExist:@"names"];
        NSArray *arr = [self.table queryAll];
        ;
        NSLog(@"%@", arr);// NSStringFromClass([arr.firstObject[@"colunms1"] class])
    });
    
//    [self.table truncate];
}


- (CustomTable *)table
{
    if (!_table) {
        _table = [[CustomTable alloc] init];
    }
    return _table;
}

@end
